﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BBMS.DLL.DataContract
{
    
    public class HoaDonNhap2: ChungTuBase
    {
        public HoaDonNhap2() 
        {
            this.LoaiCT = "HDN";
            this.IsChi = true;
        }

       public HoaDonNhap2(long id, string maCT, string soCT,
            DateTime ngayCT, DateTime ngayHT, DateTime ngayTTDuKien, 
            DateTime ngayTT, TrangThaiThanhToan trangThaiTT, 
            string maSoHS, string maNCC, string maQuay,
            long giatriHangHoa, long chietKhau,
            long giaTriChuaThue, int thueSuat, long giaTriThue,
            long giaTriCT, long giaTriDaTT, string ghiChu,
            int nvID) : base (id,"HDN",maCT,soCT,ngayCT,ngayHT,ngayTTDuKien,ngayTT,trangThaiTT,maSoHS,
           maNCC,maQuay,"",giatriHangHoa,chietKhau,giaTriChuaThue,thueSuat,giaTriThue,giaTriCT,
           giaTriDaTT,"",false,true,ghiChu,nvID)
        {
            this.LoaiCT = "HDN";
            this.IsChi = true;
           
        }

        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable(this.TableName);

            dt.Columns.Add("ID", typeof(String));
            dt.Columns.Add("MaCT", typeof(String));
            dt.Columns.Add("SoCT", typeof(String));
            dt.Columns.Add("LoaiCT", typeof(String));
            dt.Columns.Add("NgayCT", typeof(DateTime));
            dt.Columns.Add("NgayHT", typeof(DateTime));
            dt.Columns.Add("NgayTTDuKien", typeof(DateTime));
            dt.Columns.Add("NgayTT", typeof(DateTime));
            dt.Columns.Add("TrangThaiTT", typeof(int));
            dt.Columns.Add("MaHoSo", typeof(String));
            dt.Columns.Add("MaNCC", typeof(String));
            dt.Columns.Add("MaQuay", typeof(String));
            
            dt.Columns.Add("GiaTriHangHoa", typeof(long));
            dt.Columns.Add("ChietKhau", typeof(long));
            dt.Columns.Add("GiaTriChuaThue", typeof(long));
            dt.Columns.Add("ThueSuat", typeof(int));
            dt.Columns.Add("GiaTriThue", typeof(long));
            dt.Columns.Add("GiaTriCT", typeof(long));
            dt.Columns.Add("GiaTriDaTT", typeof(long));

            dt.Columns.Add("GhiChu", typeof(String));
            dt.Columns.Add("IsChi", typeof(bool));
            
            dt.Columns.Add("NVID", typeof(int));

            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["ID"] = this.ID;
            row["MaCT"] = this.MaCT;
            row["SoCT"] = this.SoCT;
            row["LoaiCT"] = "HDN";
            row["NgayCT"] = this.NgayCT;
            row["NgayHT"] = this.NgayHT;
            row["NgayTTDuKien"] = this.NgayTTDuKien;
            row["NgayTT"] = this.NgayTT;
            row["TrangThaiTT"]= (int)this.TrangThaiTT;
            row["MaHoSo"] = this.MaHoSo;
            row["MaNCC"] = this.MaNCC;
            row["MaQuay"] = this.MaQuay;

            row["GiaTriHangHoa"] = this.GiaTriHangHoa;
            row["ChietKhau"] = this.ChietKhau;
            row["GiaTriChuaThue"] = this.GiaTriChuaThue;
            row["ThueSuat"] = this.ThueSuat;
            row["GiaTriThue"] = this.GiaTriThue;
            row["GiaTriCT"] = this.GiaTriCT;
            row["GiaTriDaTT"] = this.GiaTriDaTT;

            row["GhiChu"] = this.GhiChu;
            row["IsChi"] = true;

            row["NVID"] = this.NVID;

            return row;
        }
        
        public override void UpdateInsertedID(MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            cmd.CommandText = "SELECT LAST_INSERT_ID()";
            this.ID = CommonTools.Helper.StringToLong(cmd.ExecuteScalar().ToString());
        }
        public override bool CanDelete(MySql.Data.MySqlClient.MySqlCommand cmd, System.Data.DataRow row)
        {
            return false;
        }
        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            HoaDonNhap2 obj = null;
            try
            {
                obj = new HoaDonNhap2(
                    CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    row["MaCT"].ToString(),
                    row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTTDuKien"],
                    (DateTime)row["NgayTT"],
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTriHangHoa"].ToString()),
                    CommonTools.Helper.StringToLong(row["ChietKhau"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriChuaThue"].ToString()),
                    CommonTools.Helper.StringToInt(row["ThueSuat"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriThue"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriCT"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriDaTT"].ToString()),
                    row["GhiChu"].ToString(),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }

        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader row)
        {
            HoaDonNhap2 obj = null;
            try
            {
                obj = new HoaDonNhap2(
                    CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    row["MaCT"].ToString(),
                    row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTTDuKien"],
                    (DateTime)row["NgayTT"],
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTriHangHoa"].ToString()),
                    CommonTools.Helper.StringToLong(row["ChietKhau"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriChuaThue"].ToString()),
                    CommonTools.Helper.StringToInt(row["ThueSuat"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriThue"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriCT"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriDaTT"].ToString()),
                    row["GhiChu"].ToString(),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
    }
}
